package com.song.pojo.bo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.song.model.Birthday;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author 宋涛
 * @version 1.0
 * @date 2020/7/28 15:05
 */
public class BirtydayTaskBO  implements Delayed {
    /**
     * 延迟时间
     */
    private  Birthday birthday;

    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private long time;



    public BirtydayTaskBO(Birthday birthday,long time, TimeUnit unit) {
       this.birthday = birthday;
        this.time = System.currentTimeMillis() + (time > 0 ? unit.toMillis(time) : 0);
    }

    @Override
    public long getDelay(TimeUnit unit) {

        return time - System.currentTimeMillis();
    }
    @Override
    public int compareTo(Delayed o) {
        BirtydayTaskBO Order = (BirtydayTaskBO) o;
        long diff = this.time - Order.time;
        if (diff <= 0) {
            return -1;
        } else {
            return 1;
        }
    }

    public Birthday getBirthday() {
        return birthday;
    }
}
